<?php

abstract class System_View_Helper_Abstract{
    /**
     * holds the model
     * 
     * @var Object - System_Database_Base
     * @access protected
     */
    protected $_model;
    
    /**
     * holds the data to be modified
     * 
     * @var Array
     * @access protected
     */
    protected $_data = array();

    /**
     * holds the rules for the view helper
     *
     * @var Mixed
     * @access protected
     */
    protected $_rules;
    
    /**
     * holds the data after it has been manipulated while preserving the original array format
     * 
     * @var Array
     * @access protected
     */
    protected $_affected_data = array();
    
    /**
     * holds the processed data taken from the affected_data property
     * 
     * @var Mixed
     * @access protected
     */
    protected $_processed_data;
    
    /**
     * sets the model property
     *
     * @param Array $model - Model to be modified
     * @access public
     * @return Object - System_Database_Base
     */
    public function setModel($model){
        $this->_model = $model;
        
        return $this;
    }
    
    /**
     * sets the data property
     *
     * @param Array $data - Data to be modified
     * @access public
     * @return Object - System_View_Helper_Abstract instance
     */
    public function setData($data){
        $this->_data = $data;
        
        return $this;
    }
    
    /**
     * sets the hyperlink rules
     *
     * @param String $rules - Rules for building each hyperlink
     * @access public
     * @return Object - System_View_Helper_Abstract instance
     */
    public function setRules($rules){
        $this->_rules = $rules;
        
        return $this;
    }
    
    /**
     * returns a list
     *
     * @param String $type  
     * @access public
     * @return RETURN TYPE
     */
    public function get($type){
        $return = '';
        
        switch($type){
            case 'processed':
                $return = $this->_processed_data;
                break;
                
            case 'affected':
                $return = $this->_affected_data;
                break;
        }

        return $return;
    }
    
    /**
     * parses a string and replaces [[var]] instances with the variable from the model  
     *
     * @param String $string - String to be searched and replaced
     * @access protected
     * @return String   
     */
    protected function trueValue($string){        
        $replace = array();
        
        preg_match_all('/(\[\[(.*?)\]\])/', $string, $matches);
        
        foreach($matches[2] as $match){
            $replace[] = $this->_model->getValue($match);
        }
        
        return str_replace($matches[1], $replace, $string);
    }
    
    /**
     * processes the view helper
     * 
     * @access public
     * @return Object - System_View_Helper_Abstract instance
     */
    abstract function process();
    
    /**
     * the process chain mehtod for the view helper
     * 
     * @access public
     * @return Object - System_View_Helper_Abstract instance
     */
    abstract function processChain();
}